﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Subtle.Domain.Services.Interfaces;
using log4net;
using System.Reflection;
using Subtle.Data.Persistence.Interfaces;
using Subtle.Domain.Models;

namespace Subtle.Domain.Services
{
	/// <summary>
	/// Media Service
	/// </summary>
	public class MediaService : IMediaService
	{
		private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

		private IRepository repository;

		/// <summary>
		/// Media Service
		/// </summary>
		/// <param name="MediaUnitOfWork"></param>
		public MediaService(IRepository repository)
		{
			this.repository = repository;
		}

		/// <summary>
		/// Save Media
		/// </summary>
		/// <param name="Media"></param>
		/// <returns>Media ID</returns>
		public int Save(Media Media)
		{
			if (repository.Save<Media>(Media))
			{
				return Media.ID;
			}
			return -1;
		}

		/// <summary>
		/// Get Media
		/// </summary>
		/// <param name="MediaID"></param>
		/// <returns></returns>
		public Media Get(int MediaID)
		{
			return (from Media in repository.Query<Media>()
					where Media.ID == MediaID
					select Media).FirstOrDefault();
		}
	}
}
